package com.starleague.hexagonal.flat.android;

import android.content.Context;
import android.content.res.Resources;
import android.util.AttributeSet;

import com.starleague.battletech.android.BattletechActivity;
import com.starleague.battletech.hexagonal.android.BattletechHexPainter;
import com.starleague.hexagonal.android.HexGridPainter;
import com.starleague.hexagonal.android.HexGridView;
import com.starleague.hexagonal.flat.IFlatHexGrid;

/**
 * A View that contains a HexGrid of Flat 2D Hexes (as opposed to pointy)
 */
public class FlatHexGridView
        extends HexGridView
{
    private final HexGridPainter hexGridPainter;
    private final BattletechHexPainter hexPainter;
    private final FlatHexGridMetrics flatHexGridMetrics;

    public FlatHexGridView(Context context, AttributeSet attrs)
    {
        this(context, attrs, 0);
    }

    public FlatHexGridView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);

        // TODO: All we really need is a HasFlatHexGrid
        BattletechActivity battletechActivity;
        if (context instanceof BattletechActivity)
        {
            battletechActivity = (BattletechActivity) context;
        }
        else
        {
            throw new RuntimeException("FlatHexGridView.initView(): context is not a [BattletechActivity]");
        }

        Resources resources = getResources();
        IFlatHexGrid flatHexGrid = battletechActivity.getHexGrid();

        this.flatHexGridMetrics = new FlatHexGridMetrics(flatHexGrid, resources);
        this.hexPainter = new BattletechHexPainter(this.flatHexGridMetrics, resources);

        this.hexGridPainter = new HexGridPainter(flatHexGrid,
                                                 this.flatHexGridMetrics,
                                                 this.hexPainter);

    }

    @Override
    protected FlatHexGridMetrics getHexGridMetrics()
    {
        return this.flatHexGridMetrics;
    }

    @Override
    protected HexGridPainter getHexGridPainter()
    {
        return this.hexGridPainter;
    }

    @Override
    protected BattletechHexPainter getHexPainter()
    {
        return this.hexPainter;
    }
}
